/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */
#pragma once

#include <memory>
#include "TextImpl.h"
#include <lib3d/hard/Texture.h>
#include <lib3d/hard/VertexBuffer.h>
#include <lib3d/hard/Manager.h>
#include <lib3d/node/Camera.h>
#include <lib3d/node/Text.h>
#include <CompilerFeatures.h>

namespace liba {

namespace font {
	class TrueType;
}

namespace lib3d {
namespace node {

struct TrueTypeTextData
{
	std::auto_ptr<hard::VertexBuffer> vb;
	std::auto_ptr<hard::Texture> tex;

	bool needRebuild;
};

struct CachedText;

class TrueTypeTextImpl
	: public TextImpl
	, public HardwareDependentObject<hard::Manager, TrueTypeTextData>
{
public:
	TrueTypeTextImpl(font::TrueType* font);
	TrueTypeTextImpl(const TrueTypeTextImpl & other);
	~TrueTypeTextImpl();

	virtual void render_to_list( hard::Hardware * hardware, TextRenderInfo* tri, hard::RenderList * render_list );
	virtual float get_text_width(const std::wstring & text);
	virtual float get_text_height();
	virtual void text_data_changed();
	virtual void change_valignment(VAlignment value) LIBA_OVERRIDE;
	
	virtual TrueTypeTextImpl * clone();
protected:
	virtual void on_add_hardware(hard::Manager::hardware_type * ha);
private:
	void rebuildHardware(hard::Hardware* ha);
	bool needRebuild;
	void rebuildText();
	font::TrueType* font;
	Camera * last_camera;
	VAlignment valignment;

	std::auto_ptr<CachedText> cachedText;
};

} // namespace node
} // namespace lib3d
} // namespace liba